home *** CD-ROM | disk | FTP | other *** search
Text File | 1999-06-25 | 8.4 KB | 332 lines | [TEXT/CWIE] |
- // ===========================================================================
- // CAppearanceApp.cp ©1994-1998 Metrowerks Inc. All rights reserved.
- // ===========================================================================
- // This file contains the starter code for an Appearance PowerPlant application
-
- #include "CAppearanceApp.h"
-
- #include <LGrowZone.h>
- #include <PP_Messages.h>
- #include <PP_Resources.h>
- #include <PPobClasses.h>
- #include <UDrawingState.h>
- #include <UMemoryMgr.h>
- #include <URegistrar.h>
-
- #include <LWindow.h>
- #include <LCaption.h>
-
- #include <UControlRegistry.h>
- #include <UGraphicUtils.h>
- #include <UEnvironment.h>
-
- #include <Appearance.h>
- #include <LDialogBox.h>
- #include <LPushButton.h>
- #include <LPictureControl.h>
- #include "LClipPicture.h"
- #include "FinderFun.h"
- #include <LStaticText.h>
-
- // put declarations for resource ids (ResIDTs) here
-
- const PP_PowerPlant::ResIDT wind_SampleWindow = 128; // EXAMPLE, create a new window
- const PP_PowerPlant::ResIDT wind_PasswordDialog = 129; // EXAMPLE, create a new window
-
- const MessageT cmd_Password = 2000; // nil
-
-
- static PP_PowerPlant::LWindow* sPasswordDialog = nil;
- static PP_PowerPlant::LWindow* sMainWindow = nil;
-
- static UInt32 sCount = 0;
- static UInt32 sIndex = 0;
- static UInt32 sState = 0;
- static Point sPoints[6];
-
-
- extern "C" void AquireTarget(PicHandle inPic, Point* outPoints, UInt32* outCount);
-
-
- // ===========================================================================
- // • Main Program
- // ===========================================================================
-
- int main()
- {
-
- SetDebugThrow_(PP_PowerPlant::debugAction_Alert); // Set Debugging options
- SetDebugSignal_(PP_PowerPlant::debugAction_Alert);
-
- PP_PowerPlant::InitializeHeap(3); // Initialize Memory Manager
- // Parameter is number of Master Pointer
- // blocks to allocate
-
- PP_PowerPlant::UQDGlobals::InitializeToolbox(&qd); // Initialize standard Toolbox managers
-
- new PP_PowerPlant::LGrowZone(20000); // Install a GrowZone function to catch
- // low memory situations.
-
- CAppearanceApp theApp; // create instance of your application
- theApp.Run();
-
- return 0;
- }
-
-
- // ---------------------------------------------------------------------------
- // • CAppearanceApp
- // ---------------------------------------------------------------------------
- // Constructor
-
- CAppearanceApp::CAppearanceApp()
- {
- if ( PP_PowerPlant::UEnvironment::HasFeature( PP_PowerPlant::env_HasAppearance ) ) {
- ::RegisterAppearanceClient();
- }
-
- RegisterClass_(PP_PowerPlant::LWindow); // You must register each kind of
- RegisterClass_(PP_PowerPlant::LCaption); // PowerPlant classes that you use
- // in your PPob resource.
- RegisterClass_(PP_PowerPlant::LDialogBox);
- RegisterClass_(PP_PowerPlant::LTabGroup);
- RegisterClass_(PP_PowerPlant::LTabGroupView);
- RegisterClass_(PP_PowerPlant::LClipPicture);
-
- // Register the Appearance Manager/GA classes
- PP_PowerPlant::UControlRegistry::RegisterClasses();
- }
-
-
- // ---------------------------------------------------------------------------
- // • ~CAppearanceApp
- // ---------------------------------------------------------------------------
- // Destructor
- //
-
- CAppearanceApp::~CAppearanceApp()
- {
- }
-
- // ---------------------------------------------------------------------------
- // • StartUp
- // ---------------------------------------------------------------------------
- // This method lets you do something when the application starts up
- // without a document. For example, you could issue your own new command.
-
- void
- CAppearanceApp::StartUp()
- {
- ObeyCommand(PP_PowerPlant::cmd_Password, nil); // EXAMPLE, create a new window
-
- StartIdling();
- }
-
- // ---------------------------------------------------------------------------
- // • SpendTime
- // ---------------------------------------------------------------------------
-
- void
- CAppearanceApp::SpendTime(const EventRecord& /* inMacEvent */)
- {
- // Click on the icon
- if ((sCount > 0) && (sState == 0))
- {
- ClickOnIcon(sPoints[sIndex]);
- sIndex++;
- }
-
- // Bring me back to the front
- if ((sCount > 0) && (sState > 30))
- {
- ProcessSerialNumber psn;
-
- MacGetCurrentProcess(&psn);
-
- SetFrontProcess(&psn);
- }
-
- // Move it to the trash
- if ((sCount > 0) && (sState > 60))
- {
- MoveFileToTrash();
-
- }
-
- // This needs to be above "Next"
- sState++;
-
- // Next
- if ((sCount > 0) && (sState > 90))
- {
- sCount--;
- sState = 0;
- }
- }
-
- // ---------------------------------------------------------------------------
- // • ListenToMessage
- // ---------------------------------------------------------------------------
-
- void
- CAppearanceApp::ListenToMessage(MessageT inMessage, void* /* ioParam */)
- {
- switch (inMessage)
- {
- case PP_PowerPlant::msg_OK:
- sPasswordDialog->DoClose();
- sPasswordDialog = nil;
- ObeyCommand(PP_PowerPlant::cmd_New, nil);
- break;
-
- case PP_PowerPlant::msg_Cancel:
- SysBeep(10);
- break;
-
- case 'Seek':
- if (sMainWindow != nil)
- {
- LClipPicture* thePicture = (LClipPicture*)sMainWindow->FindPaneByID(256);
- ThrowIfNil_(thePicture);
-
- PicHandle thePict = thePicture->GetPicture();
-
- if (thePict != nil)
- {
- sCount = 0;
- sState = 0;
- sIndex = 0;
-
- // Lets go hunting!
- AquireTarget(thePict, sPoints, &sCount);
-
- }
- }
- break;
-
- default:
- break;
- };
- }
-
- // ---------------------------------------------------------------------------
- // • ObeyCommand
- // ---------------------------------------------------------------------------
- // This method lets the application respond to commands like Menu commands
-
- Boolean
- CAppearanceApp::ObeyCommand(
- PP_PowerPlant::CommandT inCommand,
- void *ioParam)
- {
- Boolean cmdHandled = true;
- LPushButton* theButton;
-
- switch (inCommand) {
-
- // Handle command messages (defined in PP_Messages.h).
- case PP_PowerPlant::cmd_Password:
- // Create a dialog to get the user's password
- sPasswordDialog = PP_PowerPlant::LWindow::CreateWindow(wind_PasswordDialog, this);
- ThrowIfNil_(sPasswordDialog);
-
- // Find the button
- theButton = (LPushButton*)sPasswordDialog->FindPaneByID(128);
- ThrowIfNil_(theButton);
-
- // This is a little weird, we hook up the app as the listener
- theButton->AddListener(this);
- break;
-
- case PP_PowerPlant::cmd_New:
- // Create a dialog to get the user's password
- sMainWindow = PP_PowerPlant::LWindow::CreateWindow(wind_SampleWindow, this);
- ThrowIfNil_(sMainWindow);
-
- // Find the button
- theButton = (LPushButton*)sMainWindow->FindPaneByID(300);
- ThrowIfNil_(theButton);
-
- // This is a little weird, we hook up the app as the listener
- theButton->AddListener(this);
- break;
-
- case PP_PowerPlant::cmd_Paste:
- if (sMainWindow != nil)
- {
- Handle tempScrap = NewHandle(0);
- SInt32 offset = 0;
-
- LClipPicture* thePicture = (LClipPicture*)sMainWindow->FindPaneByID(256);
- ThrowIfNil_(thePicture);
-
- LoadScrap();
-
- GetScrap(tempScrap, 'PICT', &offset);
-
- if (GetHandleSize(tempScrap) != 0)
- thePicture->SetPicture((PicHandle)tempScrap);
-
- LStaticText* hiddenText = (LStaticText*)sMainWindow->FindPaneByID(400);
- ThrowIfNil_(hiddenText);
-
- hiddenText->Show();
-
- hiddenText = (LStaticText*)sMainWindow->FindPaneByID(401);
- ThrowIfNil_(hiddenText);
-
- hiddenText->Show();
- }
- break;
-
- // Any that you don't handle, such as cmd_About and cmd_Quit,
- // will be passed up to LApplication
- default:
- cmdHandled = PP_PowerPlant::LApplication::ObeyCommand(inCommand, ioParam);
- break;
- }
-
- return cmdHandled;
- }
-
- // ---------------------------------------------------------------------------
- // • FindCommandStatus
- // ---------------------------------------------------------------------------
- // This function enables menu commands.
- //
-
- void
- CAppearanceApp::FindCommandStatus(
- PP_PowerPlant::CommandT inCommand,
- Boolean &outEnabled,
- Boolean &outUsesMark,
- PP_PowerPlant::Char16 &outMark,
- Str255 outName)
- {
-
- switch (inCommand) {
-
- case PP_PowerPlant::cmd_New:
- if (sPasswordDialog == nil)
- outEnabled = true;
- break;
-
- case PP_PowerPlant::cmd_Paste:
- if (sMainWindow != nil)
- outEnabled = true;
- break;
-
- // Return menu item status according to command messages.
- case PP_PowerPlant::cmd_Password:
- outEnabled = true;
- break;
-
- // Any that you don't handle, such as cmd_About and cmd_Quit,
- // will be passed up to LApplication
- default:
- PP_PowerPlant::LApplication::FindCommandStatus(inCommand, outEnabled,
- outUsesMark, outMark, outName);
- break;
- }
- }
-